package com.ctsi.security.manager.impl;

import com.ctsi.security.domain.RoleDataObject;
import com.ctsi.security.domain.RolePermission;

import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CacheRole implements Serializable {

	/**
	 *serialVersionUID
	 */
	private static final long serialVersionUID = 4695394288216690112L;

	private String roleId;

	private List<String> permissionIds;
	
	private List<RolePermission> rolePermissions;

	public CacheRole(String roleId) {
		this.roleId = roleId;
	}

	public List<String> getPermissionIds() {
		return permissionIds;
	}

	public void setPermissionIds(List<String> permissionIds) {
		if (permissionIds != null) {
			Collections.sort(permissionIds);

			this.permissionIds = permissionIds;
		} else {
			this.permissionIds = Collections.<String> emptyList();
		}
	}

	public List<RoleDataObject> getDataObjectIds() {
		// 判断是否为空
		return dataObjectIds;
	}

	public void setDataObjectIds(List<RoleDataObject> dataObjectIds) {
		if (dataObjectIds != null) {
			Collections.sort(dataObjectIds, new Comparator<RoleDataObject>() {
				public int compare(RoleDataObject first, RoleDataObject second) {
					return first.getSortfactor().compareTo(second.getSortfactor());
				}
			});
			this.dataObjectIds = dataObjectIds;

		} else {
			this.dataObjectIds = Collections.<RoleDataObject> emptyList();
		}
	}

	private List<RoleDataObject> dataObjectIds;

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public List<RolePermission> getRolePermissions() {
		return rolePermissions;
	}

	public void setRolePermissions(List<RolePermission> rolePermissions) {
		if (rolePermissions != null) {
			this.rolePermissions = rolePermissions;
		} else {
			this.rolePermissions = Collections.<RolePermission> emptyList();
		}
	}

}
